import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

import router from "./router/index";
 import { createMetaManager} from 'vue-meta'
// import VueMeta from 'vue-3-meta'

const app = createApp(App);

const resolver = {
    resolve(componentInstance:any) {
      return {
        title:componentInstance.title,
        keywords:'',
        description: componentInstance.description,
      };
    },
  };
router.beforeEach((to, from, next) => {
    console.log(from);
    let keywords=to.meta.description;
    if (to.meta.title) {
      document.title = to.meta.title.toString();
    } else {
      document.title = '网站名称';
    }

    if (to.meta.keywords) {        
      const keywordsMeta = document.getElementById('keywords');
          if(keywordsMeta!=null){
            // 设置新的关键词
            keywordsMeta.setAttribute('content', to.meta.keywords.toString())
        }
    }
    if (to.meta.description) {
        
      const descriptionMeta = document.getElementById('description');
      if(descriptionMeta!=null){
        // 设置新的描述
        descriptionMeta.setAttribute('content', to.meta.description.toString())
      }
    }
    next();
  });
app.use(ElementPlus);
app.use(router);
app.use(createMetaManager({meta: { tag: 'meta', nameless: true }},resolver));
// app.use(VueMeta);
app.mount("#app");
